<template>
	<view>
		<view>
			<!-- url为要跳转外链的地址-->
			<web-view :src="url">
			</web-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: ""
			}
		},
		onLoad(val) {
			this.url = decodeURIComponent(val.url);
			// 设置当前的title 如果外链中有的话将被覆盖
			if(this.isNotEmpty(val.title)){
				this.setTitle(val.title);
			}
		},
		onShow:function(){
			this._getUrl()
		},
		methods: {
			_getUrl() {
				let bizUserId = uni.getStorageSync('bizUserId')
				uni.request({
					method: 'POST',
					url: 'https://wlreaohs.xiaomy.net/common/biz/cloud/member/signContract',
					data: {
						bizUserId: bizUserId,
						source: 1,
						jumpUrl: 'https://sndfamily-test.mynatapp.cc/stu_side_h5/xj/authorize.html'
					},
					header: { 'content-type': 'application/json' },
					success: (res) => {
						console.log(res)
						if(res.data.code == 0) {
							this.url = res.data.data.url
						} else {
							uni.showModal({
								title: '温馨提示',
								content: `${res.data.msg}`,
								showCancel: false,
								success: function (res) {
									if (res.confirm) {
										uni.switchTab({
											url: '/pages/me/me'
										})
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					},
					fail: (err) => {
						uni.hideLoading()
						console.log(err)
					}
				})
			},
			isNotEmpty(obj) {
				if (typeof obj == undefined || obj == null || obj == "" || obj == "undefined" || obj.length == 0) {
					return false;
				} else {
					return true;
				}
			},
			// 设置title
			setTitle(title) {
				uni.setNavigationBarTitle({
					title: title
				})
			},
		}
	}
</script>

<style>
</style>
